using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace cb0tServer
{
    class Kiddys
    {
        private static List<MuzzledUserItem> kiddy_items = new List<MuzzledUserItem>();

        public static bool IsKiddied(UserObject userobj)
        {
            foreach (MuzzledUserItem m in kiddy_items)
            {
                if (m.guid.Equals(userobj.guid) || m.ip.Equals(userobj.physical_ip))
                {
                    return true;
                }
            }

            return false;
        }

        public static void AddKiddy(UserObject userobj)
        {
            foreach (MuzzledUserItem m in kiddy_items)
            {
                if (m.guid.Equals(userobj.guid) ||
                    m.ip.Equals(userobj.physical_ip))
                {
                    return;
                }
            }

            MuzzledUserItem mu = new MuzzledUserItem();
            mu.name = userobj.name;
            mu.guid = userobj.guid;
            mu.ip = userobj.physical_ip;
            mu.muzzle_time = (int)cb0tServer.Helpers.UnixTime();
            kiddy_items.Add(mu);
        }

        public static void RemKiddy(UserObject userobj)
        {
            for (int i = 0; i < kiddy_items.Count; i++)
            {
                if (kiddy_items[i].guid.Equals(userobj.guid) ||
                    kiddy_items[i].ip.Equals(userobj.physical_ip))
                {
                    kiddy_items.RemoveAt(i);
                    return;
                }
            }
        }

        public static void ClearKiddys()
        {
            kiddy_items.Clear();

            foreach (UserObject u in UserPool.Users)
            {
                if (u.IsSet())
                {
                    if (u.logged_in)
                    {
                        if (u.kiddied)
                        {
                            u.kiddied = false;
                        }
                    }
                }
            }
        }
    }
}
